class Solution(object):
    def subsetsWithDup(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        n = len(nums)
        nums.sort()
        return_set = set()
        return_set.add(())
        def digui(i):
            if i < n:
                new_return_set = set()
                for item in return_set:
                    new_item = item + (nums[i],)
                    new_return_set.add(new_item)
                return_set.update(new_return_set)
                digui(i + 1)

        digui(0)
        return_list = []
        for item in return_set:
            return_list.append(list(item))
        return return_list


data = Solution()
nums = [2, 2, 1]
print(data.subsetsWithDup(nums))
